<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>事件冒泡和默认行为</title>
    <style>
        .parent {
            width: 500px;
            height: 500px;
            background-color: black;
        }

        .son {
            width: 300px;
            height: 300px;
            background-color: wheat;
        }
    </style>
</head>
<body>
<div class="parent" id="parent">
    <div class="son" id="son"></div>
</div>
<a href="https://www.baidu.com" id="son2">baidu</a>
<script>
    //    var parent = document.getElementById();
    var parent = document.querySelector('#parent');
    var son = document.querySelector('#son');
    var son2 = document.querySelector('#son2');
    parent.addEventListener('click', function () {
        alert('parent');
    });
    son.addEventListener('click', function (e) {
        e = e || window.event;
        if (e.stopPropagation) {
            e.stopPropagation();
        } else {
            e.cancelBubble = true;
        }
        alert('son');
    });

    son2.addEventListener('click', function (e) {
        e = e || window.event;
        if(e.preventDefault){
            e.preventDefault();
        }else{
            e.returnValue = false;
        }
        return false;
    });
</script>
</body>
</html>